// pages/me/index.js
const util = require('../../utils/util.js');
const apiUrl = require('../../utils/apiUrl.js');
var http = require('../../utils/httpHelper.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    winWidth: 0,
    winHeight: 0,
    isYmhShow:false,
    userInfo: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }
    });
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;

    //获取用户信息
    http.ApiGet(apiUrl.UrlUserInfo, {}, function (res) {
      // console.log(res);
      if (res.result.errorCode == 1) {
        var user = res.user;
        that.setData({
          userInfo: user,
        });
        wx.setStorageSync("user", user);

      } else {
        wx.reLaunch({
          url: '../login/index'
        })
      }
    });

    var isCheck = wx.getStorageSync("isCheck");
    this.setData({
      isYmhShow: !isCheck,
    });
    
    // wx.setNavigationBarColor({
    //   frontColor: '#ffffff', // 必写项
    //   backgroundColor: '#3b85e9', // 必写项
    // });

  },
  bindPageTap: function () {
    console.log("跳转云媒号主页页面");
    var user = wx.getStorageSync("user");
    if (user) {
      var link = "https://v.sogx.cn/wap/main/index/id/" + user.id;
      wx.navigateTo({
        url: '../webview/index?url=' + link
      })
    }
  },
  //事件处理函数
  bindSettingTap: function () {
    console.log("跳转设置页面");
    wx.navigateTo({
      url: '../me/setting'
    })
  },
  bindAvatarTap: function () {
    console.log("跳转用户信息页面");
    wx.navigateTo({
      url: '../me/info'
    })
  },
  bindNoticeTap: function () {
    wx.switchTab({
      url: '../notice/index',
    })
  },
  bindActivityTap: function () {
    wx.navigateTo({
      url: '../activity/index',
    })
  },
  bindWishTap: function () {
    wx.navigateTo({
      url: '../wish/index',
    })
  },
})